package com.design.principle.dependencyInversion;

/**
 * @program: designPattern
 * @description:
 * @author: STU756
 * @create: 2021-01-18 23:56
 */
public class Tom {
    private ICourse course = new JavaCourse();

    public Tom() {
    }

    public Tom(ICourse course) {
        this.course = course;
    }

    public void setICourse(ICourse course) {
        this.course = course;
    }

    public void study(){
        this.course.study();
    }

    //使用依赖注入的方式实现了依赖倒置
    //依赖注入有两种方法进行注入：1.通过构造器注入；2.通过set方法
    public void study(ICourse course) {
        if(course == null) {
            this.course.study();
        }else {
            course.study();
        }
    }
}
